﻿using DirectUI.Mobile.UI;
using System;
using System.Reflection;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using DirectUI.Mobile.UI.Controls;
//namespace CPICOrder.Pages
//{
//    class BasicInfo : DirectUI.Controls.Page
//    {
//        BasicInfo(string name)
//            : base(name)
//        {
//        }
//    }
//}
namespace UnitTest
{
    
    
    /// <summary>
    ///This is a test class for PageBuiderTest and is intended
    ///to contain all PageBuiderTest Unit Tests
    ///</summary>
    [TestClass()]
    public class PageBuiderTest
    {



        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for BuildPage
        ///</summary>
        [TestMethod()]
        public void BuildPage_Parse_List_With_One_XMLDataSource_Test()
        {
            //  string className = "CPICOrder.Pages.BasicInfo";

            //var ctor = Type.GetType(className).GetConstructor(new Type[] { typeof(string) });

            PageBuider target = new PageBuider(); // TODO: Initialize to an appropriate value
            Page page = target.BuildPageFromXml(DirectUIUnitTest.Resource1.ListTest);
            Assert.AreEqual("List", page.Name);
            DirectUIListBox list = (DirectUIListBox)page.FindControl("MessageList");
            Assert.IsNotNull(list);

            Assert.IsTrue(GlobeDataSourcePool.Instance.DataSourceCollection.ContainsKey("dataSource1"));
            Assert.AreEqual(1, list.BindingCollection.Count);
            Assert.IsNotNull(list.BindingCollection["DataSource"].DataSource);
            page.DataBind();
            Assert.IsTrue(list.ItemCount > 1);
            //Assert.AreEqual(typeof(HUBEIJJ.ZHFA.Pages.BasicInfo), page.GetType());
            //Assert.AreEqual(page.Components.Count , 13);

        }
        [TestMethod()]
        public void BuildPageTest1()
        {
            //  string className = "CPICOrder.Pages.BasicInfo";

            //var ctor = Type.GetType(className).GetConstructor(new Type[] { typeof(string) });

            //PageBuider target = new PageBuider(); // TODO: Initialize to an appropriate value
            //Page page = target.BuildPage(@"F:\work\太平洋保险\src\CPICOrder\pages\BasicInfo.xml");
            //Assert.AreEqual(typeof(HUBEIJJ.ZHFA.Pages.BasicInfo), page.GetType());
            //Assert.IsTrue(PageManager.Instance.DataSourceCollection["dataSource1"] != null);
            //object acutal = ((DirectUI.Mobile.UI.ObjectDataProvider)PageManager.Instance.DataSourceCollection["dataSource1"]).Data;
            // // Assert.AreEqual(15,((CPICOrder.ObjectDataProviderTestData)acutal).Value);
            //Assert.AreEqual(15, acutal);
            //DirectUITextBox lb = (DirectUITextBox)page.FindControl("tbTel1");
            //Assert.AreEqual("15", lb.Text);
            //DirectUIComboBox cb = (DirectUIComboBox)page.FindControl("cbMark");
            //Assert.AreEqual(2, cb.Items.Count);
            //Assert.AreEqual("hello", ((DirectUIComboBoxItem)cb.Items[0]).Text);
        }
    }
}
